package com.ecoolex.hotel.saas.api.graphql;

import java.util.List;

import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.NonNull;

import com.ecoolex.framework.common.annotation.Description;
import com.ecoolex.framework.modularize.api.service.storage.StorageInfo;
import com.ecoolex.framework.modularize.api.service.storage.StorageService;
import com.ecoolex.framework.web.api.graphql2.annotation.GraphQL2Module;
import com.ecoolex.framework.web.api.graphql2.annotation.GraphQL2Module.Type;
import com.ecoolex.framework.web.api.graphql2.annotation.QueryField;
import com.ecoolex.framework.web.api.graphql2.annotation.Source;
import com.ecoolex.framework.web.api.graphql2.annotation.TypeField;
import com.ecoolex.hotel.saas.entity.StoreAd;
import com.ecoolex.hotel.saas.ws.StoreAdService;


@GraphQL2Module(type = Type.User, description = "商户广告")
public class StoreAdGraphql {

    @Reference
    private StoreAdService storeAdService;

    @Autowired
    private StorageService storageService;

     @TypeField(type = StoreAd.class, field = "image", description = "广告图")
     public StorageInfo image(@Source StoreAd source) {
    	 return storageService.get(source.getImage());
     }
    
     @QueryField(field = "storeAdList", description = "广告")
     public List<StoreAd> query(@NonNull Integer storeId, 
    	 @Description({ "广告位置" }) @NonNull String position, 
    	 @Description({"广告位置的值,可以多个" }) String[] positionValue, 
    	 @Description({ "获取条数" }) @NonNull int size) {
    	 return storeAdService.queryEffectiveAd(storeId, position, positionValue, size);
     }

}
